package com.cy.pj.sys.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    //获取所有菜单信息,包含当前菜单对应的上级菜单的菜单名称
    @RequestMapping("/doFindObjects")
    public JsonResult doFindObjects(){
        return new JsonResult(sysMenuService.findObjects());
    }

    //删除菜单信息,如果当前菜单有子菜单,则不让删除
    @RequestMapping("/doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        sysMenuService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    //基于客户端请求,访问业务层对象方法,获取菜单节点对象,并封装返回
    @RequestMapping("/doFindZtreeMenuNodes")
    public JsonResult doFindZTreeMenuNodes(){
        return new JsonResult(sysMenuService.findZTreeMenuNodes());
    }

    //接收客户端提交的菜单数据，并对其进行封装，
    //然后调用业务层对象进行业务处理，最后将业务层处理结果响应到客户端。
    @RequestMapping("/doSaveObject")
    public JsonResult doSaveObject(SysMenu entity){
        sysMenuService.saveObject(entity);
        return new JsonResult("save ok");
    }

    //接收客户端提交的菜单数据，并对其进行封装，
    // 然后调用业务层对象进行业务处理，最后将业务层处理结果响应到客户端
    @RequestMapping("/doUpdateObject")
    public JsonResult doUpdateObject(SysMenu entity){
        sysMenuService.updateObject(entity);
        return new JsonResult("update ok");
    }
}
